package com.wc.AlgoOJ._DFS.AG0306;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 * @Author congege
 * @Description ICPC
 * http://43.138.190.70:8888/p/AG0306
 * @Date Created in 2023/12/20-19:40
 */
public class Main {
    static FastReader in = new FastReader();
    static int n, m;
    static char[] chs;
    static char[][] map;
    static long ans = 0;
    static int[] positionX = new int[]{-1, 0, 1, 0};
    static int[] positionY = new int[]{0, 1, 0, -1};
    static boolean[][] vis = new boolean[100][100];

    public static void main(String[] args) {
        chs = "ICPC".toCharArray();
        n = in.nextInt();
        m = in.nextInt();
        map = new char[n][m];
        for (int i = 0; i < n; i++) {
            map[i] = in.nextLine().toCharArray();
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                dfs2(i, j);
            }
        }
        System.out.println(ans);
    }

    static void dfs2(int x, int y) {
        if (map[x][y] == chs[0]) {
            dfs2(x, y, 1);
        }
    }

    static void dfs2(int x, int y, int pos) {
        vis[x][y] = true;
        for (int i = 0; i < 4; i++) {
            int nextX = x + positionX[i];
            int nextY = y + positionY[i];
            if (!isBorder(nextX, nextY) && !vis[nextX][nextY] && map[nextX][nextY] == chs[pos]) {
                if (pos == 3) {
                    ans++;
                } else {
                    dfs2(nextX, nextY, pos + 1);
                }
            }
        }
        vis[x][y] = false;
    }

    static void dfs(int x, int y, int pos) {
        if (isBorder(x, y) || vis[x][y]) {
            return;
        }

        if (map[x][y] == chs[pos]) {
            if (pos == 3) {
                ans++;
                return;
            }
            vis[x][y] = true;
            for (int i = 0; i < 4; i++) {
                int nextX = x + positionX[i];
                int nextY = y + positionY[i];
                dfs(nextX, nextY, pos + 1);
            }
            vis[x][y] = false;
        }
    }

    static boolean isBorder(int x, int y) {
        return x < 0 || x == n || y < 0 || y == m;
    }
}


class FastReader {
    StringTokenizer st;
    BufferedReader br;

    public FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }
}